/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgt.onlinetest.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 *
 * @author Administrator
 */
public class RandomHelper {

    public static final String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    public static String getRndString(int length) {
        StringBuilder sb = new StringBuilder(length);
        Random rnd = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(alphabet.charAt(rnd.nextInt(alphabet.length())));
        }
        return sb.toString();
    }

    public static <T> List<T> getRndSubSet(List<T> all, int count) {
        List<T> result = new ArrayList<T>(all);
        Random rnd = new Random();
        for (int i = 0; i < count - all.size(); i++) {
            result.remove(rnd.nextInt(result.size()));
        }
        return result;
    }
}
